package com.doge.calcalbum.core

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.doge.calcalbum.business.calc.CalcController
import com.doge.calcalbum.business.sysalbum.SysAlbumActivity
import com.doge.calcalbum.business.sysalbum.SysAlbumRepository
import com.doge.calcalbum.utils.Activities
import com.doge.calcalbum.utils.AppGuideUtils
import com.doge.calcalbum.utils.log

class AppLifecycleObserver : LifecycleObserver {
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun onAppPause() {
        AppLifecycle.onStop()
        log("onAppPause")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun onAppResume() {
        AppLifecycle.onStart()
        log("onAppResume")
        if (Activities.contains(SysAlbumActivity::class.java)) {
            SysAlbumRepository.get().refresh()
        }

        if (!calcPermissionRequiring &&
                !isSharingApp && AppGuideUtils.hasGuideAlbum) {
            CalcController.notifyIntercept(true)
        }
        isSharingApp = false
        calcPermissionRequiring = false
    }
}

var calcPermissionRequiring = false
var isSharingApp = false